//
//  NMyArticleViewController.m
//  News
//
//  Created by zhangtao on 2018/10/16.
//  Copyright © 2018年 zt.td. All rights reserved.
//

#import "NMyArticleViewController.h"
#import "NMainOneImgCell.h"
#import "NMainThreeImgCell.h"
#import "NMainNoImgCell.h"
#import "NMyArticleCommentCell.h"
#import "NWalletDetailHeaderView.h"

@interface NMyArticleViewController ()<UITableViewDelegate,UITableViewDataSource>

#define oneImgIdentifier @"oneImgIdentifier"
#define threeImgIdentifier @"threeImgIdentifier"
#define noImgIdentifier @"noImgIdentifier"
#define commentIdentifier @"commentIdentifier"
@property(nonatomic,strong)UITableView *table;
@property(nonatomic,assign)NSInteger type;
@end

@implementation NMyArticleViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"我的文章";
    NWalletDetailHeaderView *top = [[NWalletDetailHeaderView alloc]initWithFrame:CGRectMake(0, navHeight, ACEWidth, 40) items:@[@"投稿",@"评论",@"草稿"]];
    [self.view addSubview:top];
    WEAKSELF;
    top.WalletDetailViewCallBack = ^(NSInteger tag) {
        weakSelf.type = tag;
        
        [weakSelf.table reloadData];
    };
    
    _table = [[UITableView alloc]initWithFrame:CGRectMake(0, navHeight+40, ACEWidth, ACEHeight-navHeight-40)  style:UITableViewStyleGrouped];
    _table.delegate = self;
    _table.dataSource = self;
    [self.view addSubview:_table];
    [_table registerNib:[UINib nibWithNibName:@"NMainOneImgCell" bundle:nil] forCellReuseIdentifier:oneImgIdentifier];
    [_table registerNib:[UINib nibWithNibName:@"NMainThreeImgCell" bundle:nil] forCellReuseIdentifier:threeImgIdentifier];
    [_table registerNib:[UINib nibWithNibName:@"NMainNoImgCell" bundle:nil] forCellReuseIdentifier:noImgIdentifier];
    
    [_table registerNib:[UINib nibWithNibName:@"NMyArticleCommentCell" bundle:nil] forCellReuseIdentifier:commentIdentifier];
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (_type == 1) {
        return 20;
    }
    return .1;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    if (_type == 1) {
        UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, ACEWidth, 20)];
        lab.textColor = MAIN_COLOR;
        lab.backgroundColor = RGB(220, 242, 232, 1);
        lab.text = @"点亮右边“v”号，评论才能被其他人看到";
        lab.textAlignment = NSTextAlignmentCenter;
        lab.font = [UIFont systemFontOfSize:12];
        return lab;
    }
    
    return [UIView new];
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (_type == 1) {
        return 110;
    }
    if (_type == 0) {
        if (indexPath.row == 0) {
            //380:110
            return ACEWidth*11/38;
        }
        
        if (indexPath.row == 1) {
            //390:180
            return ACEWidth*18/39;
        }
        
        if (indexPath.row == 2) {
            //380:120
            return ACEWidth*5/19;
        }
    }
   
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (_type == 1) {
        NMyArticleCommentCell *cell = [tableView dequeueReusableCellWithIdentifier:commentIdentifier];
        return cell;
    }
    
    if (_type == 0) {
        if (indexPath.row == 0) {
            NMainOneImgCell *cell = [tableView dequeueReusableCellWithIdentifier:oneImgIdentifier];
            return cell;
        }
        
        if (indexPath.row == 1) {
            NMainThreeImgCell *cell = [tableView dequeueReusableCellWithIdentifier:threeImgIdentifier];
            return cell;
        }
        
        if (indexPath.row == 2) {
            NMainNoImgCell *cell = [tableView dequeueReusableCellWithIdentifier:noImgIdentifier];
            return cell;
        }
    }
    
  
    
    return nil;
}


@end
